<?php
/**
 * Manage/track webmaster data in NATS4 affiliate tracking system database
 * 
 * @name		track/edit affiliate info
 * @version		1.1
 * @package		nats-space
 * @see			http://code.google.com/p/nats-space/
 * @copyright	2009
 * @author		Joseph C. <joseph.cheys@gmail.com>
 */
class Nats4space_Affiliates
{
    /**
     * @var Zend_Db_Adapter_Mysql
     */
    private $_db;
    
    /**
     * assigns MySQL connection adapter instance
     * 
     * @param $db database adapter
     * @return
     */
    public function __construct(Zend_Db_Adapter_Abstract $db)
    {
        $this->_db = $db;
    }
    
    /**
     * Checks either webmaster login registered or not
     * 
     * @param $login webmaster login to check
     * @return boolean returns true is exists or false otherwise
     */
    public function isRegisterred($login)
    {
        $sql = '
            SELECT 
                *
            FROM 
                login 
            WHERE 
                username = ?';
        
        $result = $this->_db->fetchRow($sql, $login);
        
        if (!empty($result) && is_array($result)) {
            return true;
        }
        
        return false;
    }
    
    /**
     * Returns the affilaite ID by provided username
     * 
     * @param string $login
     * @return string affiliate ID
     */
    public function getId($login)
    {
    	$sql = '
    		SELECT
    			loginid
    		FROM
    			login
    		WHERE
    			username = ?';
    	
    	return $this->_db->fetchOne($sql, $login);
    }
}